#ifndef _NFILE_H_
#define _NFILE_H_
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
#include <stddef.h>
#include <stdarg.h>
/* typedef -------------------------------------------------------------------*/
/* define --------------------------------------------------------------------*/
/* macro ---------------------------------------------------------------------*/
/* variables -----------------------------------------------------------------*/
struct stat  
{   
    // dev_t       st_dev;     /* ID of device containing file -文件所在设备的ID*/  
    // ino_t       st_ino;     /* inode number -inode节点号*/    
    // mode_t      st_mode;    /* protection -保护模式?*/    
    // nlink_t     st_nlink;   /* number of hard links -链向此文件的连接数(硬连接)*/    
    // uid_t       st_uid;     /* user ID of owner -user id*/    
    // gid_t       st_gid;     /* group ID of owner - group id*/    
    // dev_t       st_rdev;    /* device ID (if special file) -设备号，针对设备文件*/    
    uint32_t    st_size;    /* total size, in bytes -文件大小，字节为单位*/    
    // blksize_t   st_blksize; /* blocksize for filesystem I/O -系统块的大小*/    
    // blkcnt_t    st_blocks;  /* number of blocks allocated -文件所占块数*/    
    // time_t      st_atime;   /* time of last access -最近存取时间*/    
    // time_t      st_mtime;   /* time of last modification -最近修改时间*/    
    // time_t      st_ctime;   /* time of last status change - */    
}; 

struct FileObj
{
    char        path[64];
    char        *compatibility;
    uint32_t    flag;
    void        *obj;
};


struct FcntlOperation
{
    int         (*open)(struct FileObj *file, int oflag, va_list args);
    size_t  	(*write)(struct FileObj *file, void *buf, size_t count);
    size_t  	(*read)(struct FileObj *file, void *buf, size_t count);
	int			(*lseek)(struct FileObj *file, int offset, int whence);
    int     	(*close)(struct FileObj *file);
	
	int 		(*fstat)(struct FileObj *file, struct stat *status);
};

struct FcntlDriver
{
    char                    *name;
    struct FcntlOperation   *ops;
};

struct File
{
    struct FileObj      obj;
    struct FcntlDriver  *driver;
};



#define FILE_DRIVER_INSTALL(driverName)	        \
    const struct FcntlDriver fileDriver##driverName __attribute__((used, __section__("file.driver.1"))) = {   \
        .name = #driverName,                      	\
        .ops = &##driverName##Ops,                	\
    }

/* function prototypes -------------------------------------------------------*/
/* functions -----------------------------------------------------------------*/

#endif
